package com.atguigu.gmall.order.controller;


import com.atguigu.gmall.order.service.OrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


@RestController
public class SplitOrderController {


    @Autowired
    OrderInfoService orderInfoService;
    /**
     * 拆单
     * @return
     */
    @PostMapping("/api/spilt/order")
    public  List<Map<String, Object>> spiltOrder(@RequestParam("orderId") Long orderId,
                             @RequestParam("wareSkuMap") String wareSkuMap){

        // skuId:  2,10,3
        // [{"wareId":"1","skuIds":["2","10"]},{"wareId":"2","skuIds":["3"]}]

        System.out.println("拆单：orderId:"+orderId);
        System.out.println("拆单：wareSkuMap:"+wareSkuMap);

        //拆单：orderId:714153198146813952
        //拆单：wareSkuMap:[{"wareId":"1","skuIds":["62"]},{"wareId":"2","skuIds":["61"]}]

        //1、处理拆单
        List<Map<String, Object>> maps = orderInfoService.spiltSaveOrder(orderId, wareSkuMap);

        //按照库存系统给我们发的sku库存分布，把当前orderId这个大单，拆成不同的子订单

        return maps;
    }
}
